package short_semester.questionnaire_planet.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import short_semester.questionnaire_planet.pojo.SingleChoiceOption;
import short_semester.questionnaire_planet.pojo.SingleChoiceQuestion;

import javax.transaction.Transactional;
import java.util.List;

public interface SingleChoiceOptionDao extends JpaRepository<SingleChoiceOption,Integer> {
    public List<SingleChoiceOption> findBySingleChoiceQuestionOrderBySequenceAsc(SingleChoiceQuestion singleChoiceQuestion);
    
    @Transactional
    @Modifying
    public void deleteBySingleChoiceQuestion(SingleChoiceQuestion question);
    
    public List<SingleChoiceOption> findBySingleChoiceQuestion(SingleChoiceQuestion question);

    @Modifying
    @Transactional
    @Query("update SingleChoiceOption o set o.count=o.count+1 where o.id=:id")
    void submitOption(Integer id);

    @Modifying
    @Transactional
    @Query("update SingleChoiceOption o set o.store=o.store-1 where o.id=:id")
    void signOption(Integer id);
    
    List<SingleChoiceOption> findBySingleChoiceQuestionAndIdIn(SingleChoiceQuestion question,List<Integer> optionIds);
}
